//
//  WCPicsCell.m
//  WC
//
//  Created by wsj2015 on 15/9/23.
//  Copyright (c) 2015年 ShanghaiCize Trade And Business Co., Ltd. All rights reserved.
//

#import "WCPicsCell.h"
#import "Macros.h"
#import "NSString+Utilities.h"
#import "WCImageView +setImage.h"
#import "JTSImageViewController.h"
#import "JTSImageInfo.h"

#define kLabelHeiht 45

@implementation WCPicsCell
{
    CGFloat _maxY;
    UIView  *_bgView;

}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self =[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //备注信息
        _label =[MyUtil createLabel:CGRectMake(15, 5,self.contentView.frame.size.width -30, kLabelHeiht) text:nil];
//        _label.backgroundColor =[UIColor greenColor];
        _label.numberOfLines = 0;
        _label.textColor =HexRGB(0x5e606f);
        [self.contentView addSubview:_label];
        
        //图片
        _bgView =[[UIView alloc]init];
    
        [self.contentView addSubview:_bgView];

       
       
      
        
    }
    return self;

}
- (void)addPics:(NSArray *)imageIdArray reloadTalbeView:(UITableView *)tableView
{
    CGFloat w =64;
    CGFloat h =64;
    CGFloat leftEdge = 15;
    CGFloat space =10;
    
    
    for (int i = 0; i <imageIdArray.count; i++) {
        UIImageView *picView =[[UIImageView alloc]init];
        picView.userInteractionEnabled =YES;
        picView.backgroundColor =[UIColor orangeColor];
        picView.frame =CGRectMake(leftEdge +(space + w)*i,1, w, h);
        UITapGestureRecognizer *tapG =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(bigButtonTapped:)];
        [picView addGestureRecognizer:tapG];
        [picView setOrderInforImageWithUrl:imageIdArray[i]];
        [_bgView addSubview:picView];
       
    }
   
}

- (void)bigButtonTapped:(UIGestureRecognizer *)tapG {
    
    UIImageView *tapView =(UIImageView *)tapG.view;
    
    // Create image info
    JTSImageInfo *imageInfo = [[JTSImageInfo alloc] init];
    imageInfo.image = tapView.image;
    imageInfo.referenceRect = tapView.frame;
    imageInfo.referenceView = tapView.superview;
    imageInfo.referenceContentMode = tapView.contentMode;
    imageInfo.referenceCornerRadius = tapView.layer.cornerRadius;
    
    // Setup view controller
    JTSImageViewController *imageViewer = [[JTSImageViewController alloc]
                                           initWithImageInfo:imageInfo
                                           mode:JTSImageViewControllerMode_Image
                                           backgroundStyle:JTSImageViewControllerBackgroundOption_Scaled];
    //    // Present the view controller.
    if (self.getVC) {
        WCNOrderDetailVC *vc =self.getVC();
        
        [imageViewer showFromViewController:(UIViewController *)vc transition:JTSImageViewControllerTransition_FromOriginalPosition];
        
    }
    
}
- (CGFloat)heightForCell
{
      return _maxY +10;

}

- (void)layoutSubviews
{
    [super layoutSubviews];
  
   
    
    CGFloat newH =[_label.text boundingRectWithSize:CGSizeMake(self.contentView.bounds.size.width-30, 50000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size.height;
    CGRect frame =  _label.frame;
    
    frame.size.height =newH;
    
    _label.frame =frame;
    
    _bgView.frame =CGRectMake(0,frame.size.height +5, _label.frame.size.width, 64);
    
    _maxY =CGRectGetMaxY(_bgView.frame);
   
    
    
}





+ (WCPicsCell *)tableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
   
    WCPicsCell *cell = [tableView dequeueReusableCellWithIdentifier:myCellId forIndexPath:indexPath];
   
    
    cell.selectionStyle =UITableViewCellEditingStyleNone;
     
    return cell;
 
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
